package com.syqc.monitor.ui.historyline

import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.syqc.comlib.base.LazyFragment
import com.syqc.comlib.databinding.IncludeRecyclerMathMBinding
import com.syqc.entity.HistoryLine
import com.syqc.monitor.R

/**
 *@Author Jasper
 *@Time   2020/8/12
 *@Desc   历史轨迹--超速
 */
class OverSpeedFragment :
    LazyFragment<IncludeRecyclerMathMBinding>(IncludeRecyclerMathMBinding::inflate) {

    private val mActivityVM by activityViewModels<LineInfoViewModel>()
    override fun initView(view: View) {
        binding.recyclerView.layoutManager = LinearLayoutManager(context)
    }

    //空布局
    private val emptyView by lazy {
        layoutInflater.inflate(
            R.layout.layout_empty_view,
            binding.recyclerView,
            false
        )
    }

    override fun initData() {
        mActivityVM.data.observe(this) {
            val dataAdapter = DataAdapter<HistoryLine.OverspeedData>(2)
            binding.recyclerView.adapter = dataAdapter
            if (it.overspeedData.isNullOrEmpty()) {
                dataAdapter.setEmptyView(emptyView)
                return@observe
            }
            val list: MutableList<HistoryLine.OverspeedData> = ArrayList()
            list.addAll(it.overspeedData)
            dataAdapter.setList(list)
        }

    }

    override fun initEvent() {

    }
}